package cn.tedu.redis.controller;

import cn.tedu.redis.service.GeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metric;
import org.springframework.data.geo.Metrics;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GeoController {
    @Autowired
    private GeoService geoService;

    @GetMapping("/geo/{key}/{x}/{y}/{radius}")
    public GeoResults<RedisGeoCommands.GeoLocation<Object>> findNearbyLocations(
            @PathVariable String key,
            @PathVariable double x,
            @PathVariable double y,
            @PathVariable long radius){
        Distance distance=new Distance(radius, Metrics.KILOMETERS);
        return geoService.findNearbyLocations(key,x,y,distance);
    }
}
